package uit.uthuoc.activity;

import com.uit.uthuoc.R;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;

public abstract class SingleFragmentActivity extends ActionBarActivity {
	
	private static final String LOG_ID = "uit.uthuoc.activity.SingleFragmentActivity";
	
	protected abstract Fragment createFragment();
	protected abstract boolean isUpButtonEnable();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		// Set ActionBar up button
		ActionBar actionBar = getSupportActionBar();
		actionBar.setDisplayHomeAsUpEnabled(isUpButtonEnable());
		
		setContentView(R.layout.single_fragment_activity);
		FragmentManager fm = getSupportFragmentManager();
		Fragment fragment = fm.findFragmentById(R.id.fragment_container);
		
		if (fragment == null) {
			Log.d(LOG_ID, "Call createFragment() method, expect return value not null");
			fragment = createFragment();
			fm.beginTransaction()
				.add(R.id.fragment_container, fragment)
				.commit();
		} else {
			Log.d(LOG_ID, "Fragment is existed: " + fragment.getId());
		}
		
	}

	
}
